<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        :root{
            --cool:#40C5F1;
            --hot:#f00;
            --grey:#423029;
            --light:#C3D0DF;
        }
        .wrap {
            width: 600px;
            margin: 50px auto;
        }

        .nav {
            display: flex;
            line-height: 40px;
            text-align: center;
        }

        .nav li {
            flex: 1;
            border: 1px solid var(--grey);
        }
        .nav .active{
            background-color: var(--cool);
            color: #fff;
        }

        .nav li+li {
            border-left: 0;
        }
        .list-wrap{
            height: 400px;
            text-align: center;
            line-height: 400px;
            border: 1px solid #423029;
            border-top: 0;
        }
        .list-wrap .list-item{
            height: 400px;
            display: none;
        }
        .list-wrap .show{
            display: block;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <ul class="nav">
            <li class="active">nav_1</li>
            <li>nav_2</li>
            <li>nav_3</li>
            <li>nav_4</li>
            <li>nav_5</li>
            <li>nav_6</li>
        </ul>
        <div class="list-wrap">
            <div class="list-item show">item_01</div>
            <div class="list-item">item_02</div>
            <div class="list-item">item_03</div>
            <div class="list-item">item_04</div>
            <div class="list-item">item_05</div>
            <div class="list-item">item_06</div>
        </div>
    </div>
</body>
<script>
    // 点击每个li 打印li本身及其下标

    var nav = document.getElementsByClassName("nav")[0];
    var liList = nav.getElementsByTagName("li");
    console.log(liList);

    var listItems = document.querySelectorAll(".list-wrap .list-item");


    // 多元素循环绑定事件
    for (let i = 0; i < liList.length; i++) {
        let li = liList[i]; // 获取每一个
        li.onclick = function () { // 给每一个绑事件

            // 先清除所有导航的样式  再把当前的变为活跃状态
            for(var j = 0; j < liList.length;j++){
                liList[j].className = "";
                // listItems[j].className = "list-item";
                listItems[j].classList.remove("show");
            }

            // this.className = "active";
            liList[i].className = "active";
            // listItems[i].className = "list-item show";
            listItems[i].classList.add("show");
        }
    }




</script>

</html>